package gui;

import generatore.Generatore;
import generatore.ManipolaFile;
import java.io.File;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Vector;
import javax.swing.JOptionPane;
import linguaggio.*;
import linguaggio.Grammatica.ErrorType;

/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
/**
 *
 * @author valerio
 */
public class Menu extends javax.swing.JFrame {

    private Vector<Token> tokens;
    private Vector<NonTerminale> nonTerminali;
    private Vector<Produzione> produzioni;
    private Vector<Produzione> produzioniErrore;
    private LinkedList<Element> parteDestraSelezionata;
    private LinkedList<Element> parteDestraSelezionata1;
    private LinkedList<SincroTripla> sincroTriple;
    private Vector<Token> left;
    private Vector<Token> right;
    private Vector<Token> nonassoc;
    private Vector<Token> marcaApertura;
    private Vector<Token> marcaChiusura;
    private Vector<Produzione> produzioniNonTerminale;
    private int tokenSelected = -1;
    private int produzioneSelezionata = -1;
    private Grammatica.ErrorType errorType;
    public final ErrorToken error = new ErrorToken();

    /**
     * Costruttore usato nel caso di definizione di una nuova grammatica
     */
    public Menu() {
        tokens = new Vector<>();
        nonTerminali = new Vector<>();
        produzioni = new Vector<>();
        produzioniErrore = new Vector<>();
        parteDestraSelezionata = new LinkedList<>();
        parteDestraSelezionata1 = new LinkedList<>();
        produzioniNonTerminale = new Vector<>();
        sincroTriple = new LinkedList<>();
        left = new Vector<>();
        right = new Vector<>();
        nonassoc = new Vector<>();
        marcaApertura = new Vector<>();
        marcaChiusura = new Vector<>();
        errorType = Grammatica.ErrorType.nothing;
        initComponents();
        jTabbedPane4.setEnabledAt(1, false);
        jTabbedPane4.setEnabledAt(2, false);
        jFileChooser1.setCurrentDirectory(new File(System.getProperty("user.dir")));
    }

    /**
     * Costruttore usato nel caso di caricamento di una grammatica
     *
     * @param g
     */
    public Menu(Grammatica g) {
        tokens = new Vector<>(g.getTerminali());
        nonTerminali = new Vector<>(g.getNonTerminali());
        left = new Vector<>(g.getLeft());
        right = new Vector<>(g.getRight());
        nonassoc = new Vector<>(g.getNonassoc());
        marcaApertura = new Vector<>();
        marcaChiusura = new Vector<>();
        produzioniNonTerminale = new Vector<>();
        errorType = g.getErrorType();

        produzioniErrore = new Vector<>();
        sincroTriple = new LinkedList<>();
        parteDestraSelezionata = new LinkedList<>();
        parteDestraSelezionata1 = new LinkedList<>();
        ricomponiProduzioni(g);
        ricomponiErrori(g);
        initComponents();
        if (errorType.equals(ErrorType.panicMode)) {
            this.panicModeRadioButton.setSelected(true);
            jTabbedPane4.setEnabledAt(1, false);
            jTabbedPane4.setEnabledAt(2, true);
        }
        if (errorType.equals(ErrorType.produzioniErrori)) {
            this.produzioniErroriRadioButton.setSelected(true);
            jTabbedPane4.setEnabledAt(1, true);
            jTabbedPane4.setEnabledAt(2, false);
        }
        if (errorType.equals(ErrorType.nothing)) {
            jTabbedPane4.setEnabledAt(1, false);
            jTabbedPane4.setEnabledAt(2, false);
        }
        jFileChooser1.setCurrentDirectory(new File(System.getProperty("user.dir")));

    }

    private void ricomponiProduzioni(Grammatica g) {
        produzioni = new Vector<>();
        Iterator<NonTerminale> it = g.getNonTerminali().iterator();
        while (it.hasNext()) {
            produzioni.addAll(it.next().getProduzioni());
        }
    }

    private void ricomponiErrori(Grammatica g) {
        LinkedList<NonTerminale> produzioniErrore;
        if (g.getErrorType().equals(ErrorType.produzioniErrori)) {
            produzioniErrore = g.getProduzioniErrore();
            Iterator<NonTerminale> it = produzioniErrore.iterator();
            while (it.hasNext()) {
                this.produzioniErrore.addAll(it.next().getProduzioni());
            }
        } else if (g.getErrorType().equals(ErrorType.panicMode)) {
            produzioniErrore = g.getProduzioniErrore();
            Iterator<NonTerminale> it = produzioniErrore.iterator();
            while (it.hasNext()) {
                sincroTriple.add(creaSincroTripla(it.next()));
            }
        }

    }

    private SincroTripla creaSincroTripla(NonTerminale nt) {
        SincroTripla s = new SincroTripla(nt);
        Iterator<Produzione> it = nt.getProduzioni().iterator();
        while (it.hasNext()) {
            Produzione p = it.next();
            if (!p.getParteDestra().getFirst().getClass().equals(ErrorToken.class) &&
                !s.getMarcaApertura().contains((Token) p.getParteDestra().getFirst())) {
                s.getMarcaApertura().add((Token) p.getParteDestra().getFirst());
            }
            if (!p.getParteDestra().getLast().getClass().equals(ErrorToken.class) &&!s.getMarcaChiusura().contains((Token) p.getParteDestra().getLast())) {
                s.getMarcaChiusura().add((Token) p.getParteDestra().getLast());
            }
        }
        return s;
    }

    /**
     * Metodo usato per inserire le produzioni nei rispettivi non terminali,
     * prima del salvataggio su file
     */
    private void riempiNonTerminali() {
        Iterator<NonTerminale> it2 = nonTerminali.iterator();
        while (it2.hasNext()) {
            NonTerminale nt2 = it2.next();
            nt2.getProduzioni().removeAllElements();
        }
        Iterator<Produzione> it = produzioni.iterator();
        while (it.hasNext()) {
            Produzione p = it.next();
            NonTerminale nt = p.getParteSinistra();
            nt.getProduzioni().add(p);
        }
    }

    /**
     * Metodo usato per inserire le produzioni di errore nei rispettivi non
     * terminali
     */
    private LinkedList<NonTerminale> salvaErrori() {
        LinkedList<NonTerminale> result = new LinkedList<NonTerminale>();
        if (this.errorType.equals(ErrorType.nothing)) {
            return null;
        } else if (this.errorType.equals(ErrorType.panicMode)) {
            Iterator<SincroTripla> it = sincroTriple.iterator();
            while (it.hasNext()) {
                SincroTripla s = it.next();
                NonTerminale nt = new NonTerminale(s.getNonTerminale().getName(), s.getNonTerminale().getThisTokenType(), s.getNonTerminale().getTypeAttribute());
                nt.getProduzioni().addAll(s.creaProduzioni());
                result.add(nt);
            }
        } else if (this.errorType.equals(ErrorType.produzioniErrori)) {
            Iterator<Produzione> it2 = produzioniErrore.iterator();
            while (it2.hasNext()) {
                boolean found = false;
                Produzione p = it2.next();
                NonTerminale nt = p.getParteSinistra();
                Iterator<NonTerminale> it3 = result.iterator();
                while (it3.hasNext()) {
                    NonTerminale nt2 = it3.next();
                    if (nt2.getName().equals(nt.getName())) {
                        nt2.getProduzioni().add(p);
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    NonTerminale nt2 = new NonTerminale(nt.getName(), nt.getThisTokenType(), nt.getTypeAttribute());
                    nt2.getProduzioni().add(p);
                    result.add(nt2);

                }

            }
        }
        return result;
    }

    private Grammatica creaGrammatica() {
        salvaErrori();
        this.riempiNonTerminali();
        Grammatica g = new Grammatica(new LinkedList(tokens), new LinkedList(nonTerminali), new LinkedList(left), new LinkedList(right), new LinkedList(nonassoc), this.errorType, salvaErrori());
        return g;
    }

    /**
     * Salva le necessarie impostazioni, crea l'oggetto Grammatica e lo salva su
     * file
     *
     * @param filename
     */
    private void saveFile(File file) {

        ManipolaFile.salvaGrammaticaBin(file.getAbsolutePath(), creaGrammatica());

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup = new javax.swing.ButtonGroup();
        jFileChooser1 = new javax.swing.JFileChooser();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTabbedPane3 = new javax.swing.JTabbedPane();
        jPanelLessico = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        tokenNameTextField = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        tokenExpressionTextField = new javax.swing.JTextArea();
        jLabel2 = new javax.swing.JLabel();
        inserisciToken = new javax.swing.JButton();
        modificaToken = new javax.swing.JButton();
        nuovoToken = new javax.swing.JButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        listToken = new javax.swing.JList(tokens);
        jLabel3 = new javax.swing.JLabel();
        rimuoviToken = new javax.swing.JButton();
        tipoToken = new javax.swing.JComboBox();
        jScrollPane11 = new javax.swing.JScrollPane();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane12 = new javax.swing.JScrollPane();
        listToken2 = new javax.swing.JList(tokens);
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jScrollPane15 = new javax.swing.JScrollPane();
        listLeft = new javax.swing.JList(left);
        jScrollPane16 = new javax.swing.JScrollPane();
        listRight = new javax.swing.JList(right);
        jScrollPane17 = new javax.swing.JScrollPane();
        listNonassoc = new javax.swing.JList(nonassoc);
        jLabel15 = new javax.swing.JLabel();
        aggiungiLeft = new javax.swing.JButton();
        aggiungiRight = new javax.swing.JButton();
        aggiungiNonAssoc = new javax.swing.JButton();
        spostaSopraLeft = new javax.swing.JButton();
        spostaSopraRight = new javax.swing.JButton();
        spostaSopraNonAssoc = new javax.swing.JButton();
        jLabel16 = new javax.swing.JLabel();
        spostaSottoLeft = new javax.swing.JButton();
        spostaSottoRight = new javax.swing.JButton();
        spostaSottoNonAssoc = new javax.swing.JButton();
        rimuoviLeft = new javax.swing.JButton();
        rimuoviRight = new javax.swing.JButton();
        rimuoviNonAssoc = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTabbedPane2 = new javax.swing.JTabbedPane();
        jPanelNT = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        nonTerminaleName = new javax.swing.JTextField();
        inserisciNT = new javax.swing.JButton();
        rimuoviNT = new javax.swing.JButton();
        jScrollPane6 = new javax.swing.JScrollPane();
        listNonTerminali = new javax.swing.JList(nonTerminali);
        tipoNT = new javax.swing.JComboBox();
        ScrollPaneProduzioni = new javax.swing.JScrollPane();
        jPanel3 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        parteSinistra = new javax.swing.JComboBox(nonTerminali);
        jLabel7 = new javax.swing.JLabel();
        jScrollPane7 = new javax.swing.JScrollPane();
        parteDestra = new javax.swing.JTextArea();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        aggiungiNTproduzione = new javax.swing.JButton();
        aggiungiTProduzione = new javax.swing.JButton();
        jScrollPane13 = new javax.swing.JScrollPane();
        listToken1 = new javax.swing.JList(tokens);
        jScrollPane14 = new javax.swing.JScrollPane();
        listNonTerminali1 = new javax.swing.JList(nonTerminali);
        aggiungiProduzione = new javax.swing.JButton();
        jScrollPane8 = new javax.swing.JScrollPane();
        listProduzioni = new javax.swing.JList(produzioni);
        rimuoviUltimoParteDestra = new javax.swing.JButton();
        ripulisciParteDestra = new javax.swing.JButton();
        eliminaProduzione = new javax.swing.JButton();
        jLabel14 = new javax.swing.JLabel();
        jScrollPane18 = new javax.swing.JScrollPane();
        jPanel8 = new javax.swing.JPanel();
        jScrollPane24 = new javax.swing.JScrollPane();
        listNonTerminali3 = new javax.swing.JList(nonTerminali);
        jLabel27 = new javax.swing.JLabel();
        jLabel28 = new javax.swing.JLabel();
        jScrollPane28 = new javax.swing.JScrollPane();
        listProduzioniNT = new javax.swing.JList(produzioniNonTerminale);
        spostaSopraNT = new javax.swing.JButton();
        spostaSottoNT = new javax.swing.JButton();
        selezionaNT = new javax.swing.JButton();
        spostaSopraProduzione = new javax.swing.JButton();
        spostaSottoProduzione = new javax.swing.JButton();
        jScrollPane5 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane9 = new javax.swing.JScrollPane();
        listProduzioni1 = new javax.swing.JList(produzioni);
        jLabel10 = new javax.swing.JLabel();
        jScrollPane10 = new javax.swing.JScrollPane();
        regolaSemantica = new javax.swing.JTextArea();
        jLabel11 = new javax.swing.JLabel();
        selezionaProduzione = new javax.swing.JButton();
        aggiungiRegola = new javax.swing.JButton();
        jLabel17 = new javax.swing.JLabel();
        produzioneSelezionataLabel = new javax.swing.JLabel();
        rimuoviRegola = new javax.swing.JButton();
        jTabbedPane4 = new javax.swing.JTabbedPane();
        jPanel7 = new javax.swing.JPanel();
        produzioniErroriRadioButton = new javax.swing.JRadioButton();
        panicModeRadioButton = new javax.swing.JRadioButton();
        produzioniErroriPane = new javax.swing.JScrollPane();
        jScrollPane19 = new javax.swing.JScrollPane();
        jPanel5 = new javax.swing.JPanel();
        jLabel18 = new javax.swing.JLabel();
        parteSinistra1 = new javax.swing.JComboBox(nonTerminali);
        jLabel19 = new javax.swing.JLabel();
        jScrollPane20 = new javax.swing.JScrollPane();
        parteDestra1 = new javax.swing.JTextArea();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        aggiungiNTproduzioneErrore = new javax.swing.JButton();
        aggiungiTProduzioneErrore = new javax.swing.JButton();
        jScrollPane21 = new javax.swing.JScrollPane();
        listToken3 = new javax.swing.JList(tokens);
        jScrollPane22 = new javax.swing.JScrollPane();
        listNonTerminali2 = new javax.swing.JList(nonTerminali);
        aggiungiProduzioneErrore = new javax.swing.JButton();
        jScrollPane23 = new javax.swing.JScrollPane();
        listProduzioniErrore = new javax.swing.JList(produzioniErrore);
        rimuoviUltimoParteDestra1 = new javax.swing.JButton();
        ripulisciParteDestra1 = new javax.swing.JButton();
        eliminaProduzioneErrore = new javax.swing.JButton();
        jLabel22 = new javax.swing.JLabel();
        aggiungiError = new javax.swing.JButton();
        spostaSopraProduzioneErrore = new javax.swing.JButton();
        spostaSottoProduzioneErrore = new javax.swing.JButton();
        sincrotriplePane = new javax.swing.JScrollPane();
        jPanel6 = new javax.swing.JPanel();
        parteSinistra2 = new javax.swing.JComboBox(nonTerminali);
        jLabel23 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        jScrollPane25 = new javax.swing.JScrollPane();
        listToken4 = new javax.swing.JList(tokens);
        jScrollPane26 = new javax.swing.JScrollPane();
        listMarcaApertura = new javax.swing.JList(marcaApertura);
        jLabel25 = new javax.swing.JLabel();
        jScrollPane27 = new javax.swing.JScrollPane();
        listMarcaChiusura = new javax.swing.JList(marcaChiusura);
        jLabel26 = new javax.swing.JLabel();
        aggiungiApertura = new javax.swing.JButton();
        aggiungiChiusura = new javax.swing.JButton();
        rimuoviApertura = new javax.swing.JButton();
        rimuoviChiusura = new javax.swing.JButton();
        salvaSincroTripla = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        salvaGrammatica = new javax.swing.JButton();
        implementaParser = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jLabel1.setText("Token");

        tokenNameTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tokenNameTextFieldActionPerformed(evt);
            }
        });

        tokenExpressionTextField.setColumns(20);
        tokenExpressionTextField.setRows(5);
        jScrollPane2.setViewportView(tokenExpressionTextField);

        jLabel2.setText("Espressione Regolare");

        inserisciToken.setText("Inserisci Token");
        inserisciToken.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                inserisciTokenActionPerformed(evt);
            }
        });

        modificaToken.setText("Modifica Token");
        modificaToken.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                modificaTokenActionPerformed(evt);
            }
        });

        nuovoToken.setText("Nuovo Token");
        nuovoToken.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nuovoTokenActionPerformed(evt);
            }
        });

        jScrollPane4.setViewportView(listToken);

        jLabel3.setText("Token Inseriti");

        rimuoviToken.setText("Rimuovi Token");
        rimuoviToken.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rimuoviTokenActionPerformed(evt);
            }
        });

        tipoToken.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "NOTHING", "INTEGER", "DOUBLE", "STRING", "OBJECT", "IGNORE" }));
        tipoToken.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tipoTokenActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelLessicoLayout = new javax.swing.GroupLayout(jPanelLessico);
        jPanelLessico.setLayout(jPanelLessicoLayout);
        jPanelLessicoLayout.setHorizontalGroup(
            jPanelLessicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelLessicoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelLessicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelLessicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jLabel1)
                        .addComponent(jLabel2)
                        .addComponent(jScrollPane2)
                        .addComponent(tokenNameTextField)
                        .addComponent(inserisciToken)
                        .addComponent(tipoToken, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(rimuoviToken, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanelLessicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addGroup(jPanelLessicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(nuovoToken, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(modificaToken, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap(594, Short.MAX_VALUE))
        );
        jPanelLessicoLayout.setVerticalGroup(
            jPanelLessicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelLessicoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelLessicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelLessicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelLessicoLayout.createSequentialGroup()
                        .addComponent(tokenNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tipoToken, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelLessicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(inserisciToken)
                    .addComponent(nuovoToken))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelLessicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rimuoviToken)
                    .addComponent(modificaToken))
                .addContainerGap(385, Short.MAX_VALUE))
        );

        jTabbedPane3.addTab("Token", jPanelLessico);

        jScrollPane12.setViewportView(listToken2);

        jLabel12.setText("Token");

        jLabel13.setText("Left");

        jScrollPane15.setViewportView(listLeft);

        jScrollPane16.setViewportView(listRight);

        jScrollPane17.setViewportView(listNonassoc);

        jLabel15.setText("NonAssoc");

        aggiungiLeft.setText("Aggiungi a Left");
        aggiungiLeft.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aggiungiLeftActionPerformed(evt);
            }
        });

        aggiungiRight.setText("Aggiungi a Right");
        aggiungiRight.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aggiungiRightActionPerformed(evt);
            }
        });

        aggiungiNonAssoc.setText("Aggiungi a NonAssoc");
        aggiungiNonAssoc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aggiungiNonAssocActionPerformed(evt);
            }
        });

        spostaSopraLeft.setText("Sposta Sopra");
        spostaSopraLeft.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                spostaSopraLeftActionPerformed(evt);
            }
        });

        spostaSopraRight.setText("Sposta Sopra");
        spostaSopraRight.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                spostaSopraRightActionPerformed(evt);
            }
        });

        spostaSopraNonAssoc.setText("Sposta Sopra");
        spostaSopraNonAssoc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                spostaSopraNonAssocActionPerformed(evt);
            }
        });

        jLabel16.setText("Right");

        spostaSottoLeft.setText("Sposta Sotto");
        spostaSottoLeft.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                spostaSottoLeftActionPerformed(evt);
            }
        });

        spostaSottoRight.setText("Sposta Sotto");
        spostaSottoRight.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                spostaSottoRightActionPerformed(evt);
            }
        });

        spostaSottoNonAssoc.setText("Sposta Sotto");
        spostaSottoNonAssoc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                spostaSottoNonAssocActionPerformed(evt);
            }
        });

        rimuoviLeft.setText("Rimuovi");
        rimuoviLeft.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rimuoviLeftActionPerformed(evt);
            }
        });

        rimuoviRight.setText("Rimuovi");
        rimuoviRight.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rimuoviRightActionPerformed(evt);
            }
        });

        rimuoviNonAssoc.setText("Rimuovi");
        rimuoviNonAssoc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rimuoviNonAssocActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel13)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(rimuoviLeft, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(spostaSottoLeft, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
                                .addComponent(jScrollPane15, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                                .addComponent(spostaSopraLeft, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGap(4, 4, 4)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel12)
                                    .addComponent(jScrollPane12, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel4Layout.createSequentialGroup()
                                            .addComponent(jLabel16)
                                            .addGap(110, 110, 110)
                                            .addComponent(jLabel15))
                                        .addGroup(jPanel4Layout.createSequentialGroup()
                                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                .addComponent(spostaSopraRight, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
                                                .addComponent(jScrollPane16, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                .addComponent(jScrollPane17, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                                                .addComponent(spostaSopraNonAssoc, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE))))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(spostaSottoRight, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
                                            .addComponent(rimuoviRight, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(spostaSottoNonAssoc, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(rimuoviNonAssoc, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                                .addContainerGap(645, Short.MAX_VALUE))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(aggiungiLeft, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(aggiungiRight, javax.swing.GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE))
                                    .addComponent(aggiungiNonAssoc, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(0, 0, Short.MAX_VALUE))))))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel12)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(aggiungiLeft)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(aggiungiRight)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(aggiungiNonAssoc)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jScrollPane12, javax.swing.GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(jLabel15)
                    .addComponent(jLabel16))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane16, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane15, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane17, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(spostaSopraLeft)
                    .addComponent(spostaSopraRight)
                    .addComponent(spostaSopraNonAssoc))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(spostaSottoLeft)
                    .addComponent(spostaSottoRight)
                    .addComponent(spostaSottoNonAssoc))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rimuoviLeft)
                    .addComponent(rimuoviRight)
                    .addComponent(rimuoviNonAssoc))
                .addGap(215, 215, 215))
        );

        jScrollPane11.setViewportView(jPanel4);

        jTabbedPane3.addTab("Precedenza", jScrollPane11);

        jScrollPane1.setViewportView(jTabbedPane3);

        jTabbedPane1.addTab("Lessico", jScrollPane1);

        jLabel4.setText("Non Terminale");

        jLabel6.setText("Non Terminali Inseriti");

        nonTerminaleName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nonTerminaleNameActionPerformed(evt);
            }
        });

        inserisciNT.setText("Inserisci Non Terminale");
        inserisciNT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                inserisciNTActionPerformed(evt);
            }
        });

        rimuoviNT.setText("Rimuovi Non Terminale");
        rimuoviNT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rimuoviNTActionPerformed(evt);
            }
        });

        jScrollPane6.setViewportView(listNonTerminali);

        tipoNT.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "NOTHING", "INTEGER", "DOUBLE", "STRING", "OBJECT" }));
        tipoNT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tipoNTActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelNTLayout = new javax.swing.GroupLayout(jPanelNT);
        jPanelNT.setLayout(jPanelNTLayout);
        jPanelNTLayout.setHorizontalGroup(
            jPanelNTLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelNTLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelNTLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel4)
                    .addComponent(inserisciNT, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(nonTerminaleName)
                    .addComponent(tipoNT, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(53, 53, 53)
                .addGroup(jPanelNTLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(rimuoviNT, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addContainerGap(606, Short.MAX_VALUE))
        );
        jPanelNTLayout.setVerticalGroup(
            jPanelNTLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelNTLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelNTLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelNTLayout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(12, 12, 12)
                        .addComponent(nonTerminaleName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(tipoNT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelNTLayout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addGap(12, 12, 12)
                        .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelNTLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(rimuoviNT)
                            .addComponent(inserisciNT))))
                .addContainerGap(488, Short.MAX_VALUE))
        );

        jTabbedPane2.addTab("Non Terminali", jPanelNT);

        jLabel5.setText("Parte Sinistra");

        parteSinistra.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                parteSinistraActionPerformed(evt);
            }
        });

        jLabel7.setText("ParteDestra");

        parteDestra.setColumns(10);
        parteDestra.setEditable(false);
        parteDestra.setRows(2);
        jScrollPane7.setViewportView(parteDestra);

        jLabel8.setText("Terminali");

        jLabel9.setText("Non Terminali");

        aggiungiNTproduzione.setText("Aggiungi Non Terminale");
        aggiungiNTproduzione.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aggiungiNTproduzioneActionPerformed(evt);
            }
        });

        aggiungiTProduzione.setText("Aggiungi Terminale");
        aggiungiTProduzione.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aggiungiTProduzioneActionPerformed(evt);
            }
        });

        jScrollPane13.setViewportView(listToken1);

        jScrollPane14.setViewportView(listNonTerminali1);

        aggiungiProduzione.setText("Aggiungi Produzione");
        aggiungiProduzione.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aggiungiProduzioneActionPerformed(evt);
            }
        });

        jScrollPane8.setViewportView(listProduzioni);

        rimuoviUltimoParteDestra.setText("Rimuovi ultimo");
        rimuoviUltimoParteDestra.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rimuoviUltimoParteDestraActionPerformed(evt);
            }
        });

        ripulisciParteDestra.setText("Ripulisci");
        ripulisciParteDestra.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ripulisciParteDestraActionPerformed(evt);
            }
        });

        eliminaProduzione.setText("Elimina Produzione");
        eliminaProduzione.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                eliminaProduzioneActionPerformed(evt);
            }
        });

        jLabel14.setText("Produzioni Inserite");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jScrollPane8)
                                .addComponent(aggiungiProduzione)
                                .addGroup(jPanel3Layout.createSequentialGroup()
                                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(parteSinistra, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel7)
                                        .addComponent(jScrollPane7, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(ripulisciParteDestra, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(rimuoviUltimoParteDestra)))
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel3Layout.createSequentialGroup()
                                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(jPanel3Layout.createSequentialGroup()
                                                .addComponent(jLabel8)
                                                .addGap(125, 125, 125))
                                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                                                .addComponent(aggiungiTProduzione, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(18, 18, 18)))
                                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel9)
                                            .addComponent(aggiungiNTproduzione, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addGroup(jPanel3Layout.createSequentialGroup()
                                        .addComponent(jScrollPane13, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jScrollPane14, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(eliminaProduzione, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(jLabel14))
                .addContainerGap(370, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(jLabel5)
                            .addComponent(jLabel7)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel9)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(parteSinistra, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rimuoviUltimoParteDestra)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ripulisciParteDestra))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane13, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)
                            .addComponent(jScrollPane14, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(aggiungiTProduzione)
                            .addComponent(aggiungiNTproduzione)
                            .addComponent(aggiungiProduzione))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(eliminaProduzione))
                .addGap(267, 267, 267))
        );

        ScrollPaneProduzioni.setViewportView(jPanel3);

        jTabbedPane2.addTab("Produzioni", ScrollPaneProduzioni);

        jScrollPane24.setViewportView(listNonTerminali3);

        jLabel27.setText("Precedenza tra Non Terminali");

        jLabel28.setText("Precedenza tra Produzioni");

        jScrollPane28.setViewportView(listProduzioniNT);

        spostaSopraNT.setText("Sposta Sopra");
        spostaSopraNT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                spostaSopraNTActionPerformed(evt);
            }
        });

        spostaSottoNT.setText("Sposta Sotto");
        spostaSottoNT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                spostaSottoNTActionPerformed(evt);
            }
        });

        selezionaNT.setText("Seleziona");
        selezionaNT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                selezionaNTActionPerformed(evt);
            }
        });

        spostaSopraProduzione.setText("Sposta Sopra");
        spostaSopraProduzione.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                spostaSopraProduzioneActionPerformed(evt);
            }
        });

        spostaSottoProduzione.setText("Sposta Sotto");
        spostaSottoProduzione.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                spostaSottoProduzioneActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel27)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addComponent(jScrollPane24, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(spostaSopraNT, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(spostaSottoNT, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(selezionaNT, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addComponent(jLabel28)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addComponent(jScrollPane28, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(spostaSopraProduzione)
                            .addComponent(spostaSottoProduzione))))
                .addContainerGap(770, Short.MAX_VALUE))
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel27)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane24, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addComponent(spostaSopraNT)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(spostaSottoNT)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(selezionaNT)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel28)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane28, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addComponent(spostaSopraProduzione)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(spostaSottoProduzione)))
                .addContainerGap(226, Short.MAX_VALUE))
        );

        jScrollPane18.setViewportView(jPanel8);

        jTabbedPane2.addTab("Precedenza", jScrollPane18);

        jScrollPane3.setViewportView(jTabbedPane2);

        jTabbedPane1.addTab("Sintassi", jScrollPane3);

        jScrollPane9.setViewportView(listProduzioni1);

        jLabel10.setText("Regola Semantica");

        regolaSemantica.setColumns(20);
        regolaSemantica.setRows(5);
        jScrollPane10.setViewportView(regolaSemantica);

        jLabel11.setText("Produzioni");

        selezionaProduzione.setText("Seleziona Produzione");
        selezionaProduzione.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                selezionaProduzioneActionPerformed(evt);
            }
        });

        aggiungiRegola.setText("Aggiungi Regola");
        aggiungiRegola.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aggiungiRegolaActionPerformed(evt);
            }
        });

        jLabel17.setText("Produzione Selezionata: ");

        produzioneSelezionataLabel.setText("Nessuna");

        rimuoviRegola.setText("Rimuovi Regola");
        rimuoviRegola.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rimuoviRegolaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jScrollPane10, javax.swing.GroupLayout.DEFAULT_SIZE, 275, Short.MAX_VALUE)
                                .addComponent(aggiungiRegola, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(rimuoviRegola, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(jLabel10))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addContainerGap())
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(selezionaProduzione, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jScrollPane9, javax.swing.GroupLayout.DEFAULT_SIZE, 301, Short.MAX_VALUE))
                                .addContainerGap(595, Short.MAX_VALUE))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel17)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(produzioneSelezionataLabel)
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel17)
                            .addComponent(produzioneSelezionataLabel))
                        .addGap(2, 2, 2)
                        .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane10, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(aggiungiRegola)
                    .addComponent(selezionaProduzione))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rimuoviRegola)
                .addContainerGap(304, Short.MAX_VALUE))
        );

        jScrollPane5.setViewportView(jPanel1);

        jTabbedPane1.addTab("Semantica", jScrollPane5);

        buttonGroup.add(produzioniErroriRadioButton);
        produzioniErroriRadioButton.setText("Produzioni di Errori");
        produzioniErroriRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                produzioniErroriRadioButtonActionPerformed(evt);
            }
        });

        buttonGroup.add(panicModeRadioButton);
        panicModeRadioButton.setText("Panic Mode");
        panicModeRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                panicModeRadioButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGap(61, 61, 61)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panicModeRadioButton)
                    .addComponent(produzioniErroriRadioButton))
                .addContainerGap(550, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGap(73, 73, 73)
                .addComponent(produzioniErroriRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panicModeRadioButton)
                .addContainerGap(424, Short.MAX_VALUE))
        );

        jTabbedPane4.addTab("Tipo", jPanel7);

        jLabel18.setText("Parte Sinistra");

        parteSinistra1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                parteSinistra1ActionPerformed(evt);
            }
        });

        jLabel19.setText("ParteDestra");

        parteDestra1.setColumns(10);
        parteDestra1.setEditable(false);
        parteDestra1.setRows(2);
        jScrollPane20.setViewportView(parteDestra1);

        jLabel20.setText("Terminali");

        jLabel21.setText("Non Terminali");

        aggiungiNTproduzioneErrore.setText("Aggiungi Non Terminale");
        aggiungiNTproduzioneErrore.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aggiungiNTproduzioneErroreActionPerformed(evt);
            }
        });

        aggiungiTProduzioneErrore.setText("Aggiungi Terminale");
        aggiungiTProduzioneErrore.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aggiungiTProduzioneErroreActionPerformed(evt);
            }
        });

        jScrollPane21.setViewportView(listToken3);

        jScrollPane22.setViewportView(listNonTerminali2);

        aggiungiProduzioneErrore.setText("Aggiungi Produzione");
        aggiungiProduzioneErrore.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aggiungiProduzioneErroreActionPerformed(evt);
            }
        });

        jScrollPane23.setViewportView(listProduzioniErrore);

        rimuoviUltimoParteDestra1.setText("Rimuovi ultimo");
        rimuoviUltimoParteDestra1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rimuoviUltimoParteDestra1ActionPerformed(evt);
            }
        });

        ripulisciParteDestra1.setText("Ripulisci");
        ripulisciParteDestra1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ripulisciParteDestra1ActionPerformed(evt);
            }
        });

        eliminaProduzioneErrore.setText("Elimina Produzione");
        eliminaProduzioneErrore.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                eliminaProduzioneErroreActionPerformed(evt);
            }
        });

        jLabel22.setText("Produzioni Inserite");

        aggiungiError.setText("Aggiungi error");
        aggiungiError.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aggiungiErrorActionPerformed(evt);
            }
        });

        spostaSopraProduzioneErrore.setText("Sposta Sopra");
        spostaSopraProduzioneErrore.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                spostaSopraProduzioneErroreActionPerformed(evt);
            }
        });

        spostaSottoProduzioneErrore.setText("Sposta Sotto");
        spostaSottoProduzioneErrore.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                spostaSottoProduzioneErroreActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jScrollPane23, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(aggiungiProduzioneErrore, javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel5Layout.createSequentialGroup()
                                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(aggiungiError, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(parteSinistra1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel18, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel5Layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel19)
                                            .addComponent(jScrollPane20, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                                        .addGap(81, 81, 81)
                                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(ripulisciParteDestra1, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(rimuoviUltimoParteDestra1))))))
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel5Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel5Layout.createSequentialGroup()
                                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(jPanel5Layout.createSequentialGroup()
                                                .addComponent(jLabel20)
                                                .addGap(125, 125, 125))
                                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                                                .addComponent(aggiungiTProduzioneErrore, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(18, 18, 18)))
                                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel21)
                                            .addComponent(aggiungiNTproduzioneErrore, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addGroup(jPanel5Layout.createSequentialGroup()
                                        .addComponent(jScrollPane21, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jScrollPane22, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(jPanel5Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(eliminaProduzioneErrore, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)
                                    .addComponent(spostaSopraProduzioneErrore, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(spostaSottoProduzioneErrore, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
                    .addComponent(jLabel22))
                .addContainerGap(370, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel20)
                            .addComponent(jLabel18)
                            .addComponent(jLabel19)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel21)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(parteSinistra1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane20, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(rimuoviUltimoParteDestra1)
                            .addComponent(aggiungiError))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ripulisciParteDestra1))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane21, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE)
                            .addComponent(jScrollPane22, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(aggiungiTProduzioneErrore)
                            .addComponent(aggiungiNTproduzioneErrore)
                            .addComponent(aggiungiProduzioneErrore))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel22)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane23, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(eliminaProduzioneErrore)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(spostaSopraProduzioneErrore)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(spostaSottoProduzioneErrore)))
                .addGap(267, 267, 267))
        );

        jScrollPane19.setViewportView(jPanel5);

        produzioniErroriPane.setViewportView(jScrollPane19);

        jTabbedPane4.addTab("Produzioni Di Errori", produzioniErroriPane);

        parteSinistra2.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                parteSinistra2ItemStateChanged(evt);
            }
        });
        parteSinistra2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                parteSinistra2ActionPerformed(evt);
            }
        });

        jLabel23.setText("Non Terminale");

        jLabel24.setText("Terminali");

        jScrollPane25.setViewportView(listToken4);

        jScrollPane26.setViewportView(listMarcaApertura);

        jLabel25.setText("Marca di Apertura");

        jScrollPane27.setViewportView(listMarcaChiusura);

        jLabel26.setText("Marca di Chiusura");

        aggiungiApertura.setText("Aggiungi ad Apertura");
        aggiungiApertura.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aggiungiAperturaActionPerformed(evt);
            }
        });

        aggiungiChiusura.setText("Aggiungi a Chiusura");
        aggiungiChiusura.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aggiungiChiusuraActionPerformed(evt);
            }
        });

        rimuoviApertura.setText("Rimuovi");
        rimuoviApertura.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rimuoviAperturaActionPerformed(evt);
            }
        });

        rimuoviChiusura.setText("Rimuovi");
        rimuoviChiusura.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rimuoviChiusuraActionPerformed(evt);
            }
        });

        salvaSincroTripla.setText("Salva");
        salvaSincroTripla.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salvaSincroTriplaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel23, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(parteSinistra2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(salvaSincroTripla, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(51, 51, 51)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addComponent(jScrollPane25, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(aggiungiApertura, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(aggiungiChiusura, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .addComponent(jLabel24)))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane26, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                            .addComponent(jLabel25)
                            .addComponent(rimuoviApertura, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel26)
                            .addComponent(jScrollPane27, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                            .addComponent(rimuoviChiusura, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE))))
                .addContainerGap(354, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel23)
                            .addComponent(jLabel24))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(parteSinistra2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(salvaSincroTripla))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addComponent(aggiungiApertura)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(aggiungiChiusura))
                            .addComponent(jScrollPane25, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel25)
                    .addComponent(jLabel26))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane26, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane27, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rimuoviApertura)
                    .addComponent(rimuoviChiusura))
                .addGap(122, 122, 122))
        );

        sincrotriplePane.setViewportView(jPanel6);

        jTabbedPane4.addTab("Sincrotriple", sincrotriplePane);

        jTabbedPane1.addTab("Gestione Errori", jTabbedPane4);

        salvaGrammatica.setText("Salva Grammatica");
        salvaGrammatica.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salvaGrammaticaActionPerformed(evt);
            }
        });

        implementaParser.setText("Implementa Parser");
        implementaParser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                implementaParserActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(implementaParser, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(salvaGrammatica, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(622, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(69, 69, 69)
                .addComponent(salvaGrammatica)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(implementaParser)
                .addContainerGap(458, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Conferma", jPanel2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 783, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 631, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void salvaGrammaticaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salvaGrammaticaActionPerformed
        jFileChooser1.showSaveDialog(null);
        File file = jFileChooser1.getSelectedFile();
        if (file != null) {
            this.saveFile(file);
        }
    }//GEN-LAST:event_salvaGrammaticaActionPerformed

    private void aggiungiRegolaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aggiungiRegolaActionPerformed

        if (produzioneSelezionata > -1) {
            if (!regolaSemantica.getText().endsWith(";")) {
                JOptionPane.showMessageDialog(null, "Regola semantica non valida", "Errore", JOptionPane.ERROR_MESSAGE);
                return;
            }
            produzioni.get(produzioneSelezionata).setRegolaSemantica(regolaSemantica.getText());
            produzioneSelezionata = -1;
            listProduzioni1.clearSelection();
            produzioneSelezionataLabel.setText("Nessuna");
            regolaSemantica.setText(null);
        } else {
            JOptionPane.showMessageDialog(null, "Nessuna Produzione Selezionata", "Errore", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_aggiungiRegolaActionPerformed

    private void selezionaProduzioneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selezionaProduzioneActionPerformed
        produzioneSelezionata = listProduzioni1.getSelectedIndex();
        if (produzioneSelezionata > -1) {
            regolaSemantica.setText(produzioni.get(produzioneSelezionata).getRegolaSemantica());
            produzioneSelezionataLabel.setText(produzioni.get(produzioneSelezionata).toString());
        }
    }//GEN-LAST:event_selezionaProduzioneActionPerformed

    private void eliminaProduzioneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_eliminaProduzioneActionPerformed
        int index = listProduzioni.getSelectedIndex();
        if (index > -1) {
            produzioni.remove(index);
        }
        listProduzioni.updateUI();
        listProduzioni1.updateUI();
    }//GEN-LAST:event_eliminaProduzioneActionPerformed

    private void ripulisciParteDestraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ripulisciParteDestraActionPerformed
        parteDestraSelezionata = new LinkedList<Element>();
        parteDestra.setText("");
    }//GEN-LAST:event_ripulisciParteDestraActionPerformed

    private void rimuoviUltimoParteDestraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rimuoviUltimoParteDestraActionPerformed
        if (!parteDestraSelezionata.isEmpty()) {
            Element e = parteDestraSelezionata.removeLast();
            String pd = parteDestra.getText();
            parteDestra.setText(pd.substring(0, pd.lastIndexOf(e.getName())));
        }
    }//GEN-LAST:event_rimuoviUltimoParteDestraActionPerformed

    private void aggiungiProduzioneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aggiungiProduzioneActionPerformed
        boolean valid = true;
        Produzione p = new Produzione((NonTerminale) parteSinistra.getSelectedItem(), parteDestraSelezionata);
        if (p.getParteSinistra() == null) {
            valid = false;
            JOptionPane.showMessageDialog(null, "Parte Sinistra o Destra vuota", "Produzione non Valida", JOptionPane.ERROR_MESSAGE);
        } else {
            Iterator<Produzione> it = produzioni.iterator();
            while (it.hasNext()) {
                Produzione produzione = it.next();
                if (produzione.toString().equals(p.toString())) {
                    valid = false;
                    JOptionPane.showMessageDialog(null, "Produzione già esistente", "Produzione non Valida", JOptionPane.ERROR_MESSAGE);
                    break;
                }
            }
        }
        if (valid) {
            produzioni.add(p);
            parteSinistra.setSelectedIndex(-1);
            parteDestraSelezionata = new LinkedList<Element>();
            parteDestra.setText("");
            listProduzioni.updateUI();
            listProduzioni1.updateUI();
        }
    }//GEN-LAST:event_aggiungiProduzioneActionPerformed

    private void aggiungiTProduzioneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aggiungiTProduzioneActionPerformed

        if (listToken1.getSelectedIndex() > -1) {
            Token token = tokens.get(listToken1.getSelectedIndex());
            parteDestra.append(token + " ");
            parteDestraSelezionata.add(token);
        }
    }//GEN-LAST:event_aggiungiTProduzioneActionPerformed

    private void aggiungiNTproduzioneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aggiungiNTproduzioneActionPerformed

        if (listNonTerminali1.getSelectedIndex() > -1) {
            NonTerminale nt = nonTerminali.get(listNonTerminali1.getSelectedIndex());
            parteDestra.append(nt + " ");
            parteDestraSelezionata.add(nt);
        }
    }//GEN-LAST:event_aggiungiNTproduzioneActionPerformed

    private void parteSinistraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_parteSinistraActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_parteSinistraActionPerformed

    private void tipoNTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tipoNTActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tipoNTActionPerformed

    private void rimuoviNTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rimuoviNTActionPerformed
        int index = listNonTerminali.getSelectedIndex();
        if ( index > -1) {
            NonTerminale nt = nonTerminali.get(index);

            //Elimino le produzioni che contengono il terminale

            Iterator<Produzione> it = produzioni.iterator();
            while (it.hasNext()) {
                Produzione p = it.next();
                if (p.getParteSinistra().equals(nt)) {
                    it.remove();
                } else {
                    if (p.getParteDestra().contains(nt)) {
                        it.remove();
                    }
                }
            }

            //Elimino le produzioni di errore che contengono il terminale
            Iterator<Produzione> it3;
            it3 = produzioniErrore.iterator();
            while (it3.hasNext()) {
                Produzione p = it3.next();
                if (p.getParteSinistra().equals(nt)) {
                    it3.remove();
                } else {
                    if (p.getParteDestra().contains(nt)) {
                        it3.remove();
                    }
                }
            }
            //Elimino le sincrotriple che contengono il terminale
            Iterator<SincroTripla> it2 = sincroTriple.iterator();
            while (it2.hasNext()) {
                SincroTripla s = it2.next();
                if (s.getNonTerminale().equals(nt)) {
                    it2.remove();
                    break;
                }
            }

            nonTerminali.remove(nt);

            listNonTerminali.clearSelection();
            listNonTerminali1.clearSelection();
            listNonTerminali2.clearSelection();
            listNonTerminali3.clearSelection();
            
            listNonTerminali.updateUI();
            listNonTerminali1.updateUI();
            listNonTerminali2.updateUI();
            listNonTerminali3.updateUI();
            
            parteSinistra.updateUI();
            parteSinistra1.updateUI();
            parteSinistra2.updateUI();
            
            listProduzioni.updateUI();
            listProduzioni1.updateUI();
        }
    }//GEN-LAST:event_rimuoviNTActionPerformed

    private void inserisciNTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inserisciNTActionPerformed
        //Aggiungo il non terminale alla mappa se non e' stato precedentemente inserito         
        boolean valid = true;
        if (nonTerminaleName.getText().length() == 0) {
            valid = false;
            JOptionPane.showMessageDialog(null, " Nome vuoto ", "Non Terminale non valido", JOptionPane.ERROR_MESSAGE);
        } else {
            Iterator<NonTerminale> it = nonTerminali.iterator();
            while (it.hasNext()) {
                if (it.next().getName().equals(nonTerminaleName.getText())) {
                    valid = false;
                    JOptionPane.showMessageDialog(null, " Esiste un Non Terminale con lo stesso nome ", "Non Terminale non valido", JOptionPane.ERROR_MESSAGE);
                }
                break;
            }
            if (valid) {
                Iterator<Token> it2 = tokens.iterator();
                while (it2.hasNext()) {
                    Token t = it2.next();

                    if (t.getName().equals(nonTerminaleName.getText())) {
                        valid = false;
                        JOptionPane.showMessageDialog(null, " Esiste un Token con lo stesso nome ", "Non Terminale non valido", JOptionPane.ERROR_MESSAGE);
                        break;
                    }
                }
            }
        }
        if (valid) {
            NonTerminale nonTerminale = new NonTerminale(nonTerminaleName.getText());
            if (tipoNT.getSelectedIndex() > -1) {

                int x = tipoNT.getSelectedIndex();
                switch (x) {
                    case 1:
                        nonTerminale.setThisTokenType(linguaggio.AttributeType.tokenType.ival);
                        break;
                    case 2:
                        nonTerminale.setThisTokenType(linguaggio.AttributeType.tokenType.dval);
                        break;
                    case 3:
                        nonTerminale.setThisTokenType(linguaggio.AttributeType.tokenType.sval);
                        break;
                    case 4:
                        nonTerminale.setThisTokenType(AttributeType.tokenType.obj);
                        nonTerminale.setTypeAttribute(JOptionPane.showInputDialog("Inserisci Nome Classe: "));
                        break;
                    case 0:
                        nonTerminale.setThisTokenType(linguaggio.AttributeType.tokenType.niente);
                        break;
                }
            }
            nonTerminali.add(nonTerminale);
            listNonTerminali.updateUI();
            listNonTerminali1.updateUI();
            listNonTerminali2.updateUI();
            listNonTerminali3.updateUI();
            parteSinistra.updateUI();
            parteSinistra1.updateUI();
            parteSinistra2.updateUI();
        }


        nonTerminaleName.setText(
                null);
        regolaSemantica.setText(
                null);



    }//GEN-LAST:event_inserisciNTActionPerformed

    private void nonTerminaleNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nonTerminaleNameActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_nonTerminaleNameActionPerformed

    private void rimuoviNonAssocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rimuoviNonAssocActionPerformed
        if (listNonassoc.getSelectedIndex() > -1) {
            nonassoc.remove(listNonassoc.getSelectedIndex());
            listNonassoc.updateUI();
        }
    }//GEN-LAST:event_rimuoviNonAssocActionPerformed

    private void rimuoviRightActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rimuoviRightActionPerformed
        if (listRight.getSelectedIndex() > -1) {
            right.remove(listRight.getSelectedIndex());
            listRight.updateUI();
        }
    }//GEN-LAST:event_rimuoviRightActionPerformed

    private void rimuoviLeftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rimuoviLeftActionPerformed
        if (listLeft.getSelectedIndex() > -1) {
            left.remove(listLeft.getSelectedIndex());
            listLeft.updateUI();
        }
    }//GEN-LAST:event_rimuoviLeftActionPerformed

    private void spostaSottoNonAssocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_spostaSottoNonAssocActionPerformed
        int startIndex = listNonassoc.getSelectedIndex();
        if (startIndex > -1 && startIndex < nonassoc.size() - 1) {
            nonassoc.set(startIndex, nonassoc.set(startIndex + 1, nonassoc.get(startIndex)));
            listNonassoc.setSelectedIndex(startIndex + 1);
            listNonassoc.updateUI();
        }
    }//GEN-LAST:event_spostaSottoNonAssocActionPerformed

    private void spostaSottoRightActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_spostaSottoRightActionPerformed
        int startIndex = listRight.getSelectedIndex();
        if (startIndex > -1 && startIndex < right.size() - 1) {
            right.set(startIndex, right.set(startIndex + 1, right.get(startIndex)));
            listRight.setSelectedIndex(startIndex + 1);
            listRight.updateUI();
        }
    }//GEN-LAST:event_spostaSottoRightActionPerformed

    private void spostaSottoLeftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_spostaSottoLeftActionPerformed
        int startIndex = listLeft.getSelectedIndex();
        if (startIndex > -1 && startIndex < left.size() - 1) {
            left.set(startIndex, left.set(startIndex + 1, left.get(startIndex)));
            listLeft.setSelectedIndex(startIndex + 1);
            listLeft.updateUI();
        }
    }//GEN-LAST:event_spostaSottoLeftActionPerformed

    private void spostaSopraNonAssocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_spostaSopraNonAssocActionPerformed
        int startIndex = listNonassoc.getSelectedIndex();
        if (startIndex > 0 && startIndex < nonassoc.size()) {
            nonassoc.set(startIndex, nonassoc.set(startIndex - 1, nonassoc.get(startIndex)));
            listNonassoc.setSelectedIndex(startIndex - 1);
            listNonassoc.updateUI();
        }
    }//GEN-LAST:event_spostaSopraNonAssocActionPerformed

    private void spostaSopraRightActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_spostaSopraRightActionPerformed
        int startIndex = listRight.getSelectedIndex();
        if (startIndex > 0 && startIndex < right.size()) {
            right.set(startIndex, right.set(startIndex - 1, right.get(startIndex)));
            listRight.setSelectedIndex(startIndex - 1);
            listRight.updateUI();
        }
    }//GEN-LAST:event_spostaSopraRightActionPerformed

    private void spostaSopraLeftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_spostaSopraLeftActionPerformed
        int startIndex = listLeft.getSelectedIndex();
        if (startIndex > 0 && startIndex < left.size()) {
            left.set(startIndex, left.set(startIndex - 1, left.get(startIndex)));
            listLeft.setSelectedIndex(startIndex - 1);
            listLeft.updateUI();
        }
    }//GEN-LAST:event_spostaSopraLeftActionPerformed

    private void aggiungiNonAssocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aggiungiNonAssocActionPerformed
        Token token = (Token) listToken2.getSelectedValue();
        if (!nonassoc.contains(token)) {
            nonassoc.add(token);
        }
        listNonassoc.updateUI();
    }//GEN-LAST:event_aggiungiNonAssocActionPerformed

    private void aggiungiRightActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aggiungiRightActionPerformed
        Token token = (Token) listToken2.getSelectedValue();
        if (!right.contains(token)) {
            right.add(token);
        }
        listRight.updateUI();
    }//GEN-LAST:event_aggiungiRightActionPerformed

    private void aggiungiLeftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aggiungiLeftActionPerformed
        Token token = (Token) listToken2.getSelectedValue();
        if (!left.contains(token)) {
            left.add(token);
        }
        listLeft.updateUI();
    }//GEN-LAST:event_aggiungiLeftActionPerformed

    private void tipoTokenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tipoTokenActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tipoTokenActionPerformed

    private void rimuoviTokenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rimuoviTokenActionPerformed
        if (tokenSelected != -1) {
            Token token = tokens.remove(tokenSelected);
            tokenSelected = -1;
            //Rimuovo tutte le produzioni che contengono il token
            Iterator<Produzione> it = produzioni.iterator();
            while (it.hasNext()) {
                Produzione p = it.next();
                if (p.getParteDestra().contains(token)) {
                    it.remove();
                }
            }
            //Rimuovo tutte le produzioni di errore che contengono il token
            Iterator<Produzione> it3;
            it3 = produzioniErrore.iterator();
            while (it3.hasNext()) {
                Produzione p = it3.next();
                if (p.getParteDestra().contains(token)) {
                    it3.remove();
                }
            }
            //Rimuovo dalle marche delle sincrotriple
            Iterator<SincroTripla> it2 = sincroTriple.iterator();
            while (it2.hasNext()) {
                SincroTripla s = it2.next();
                s.getMarcaApertura().remove(token);
                s.getMarcaChiusura().remove(token);
            }
            marcaApertura.remove(token);
            marcaChiusura.remove(token);
            //Rimuovo dalle tre liste di precedenza
            left.remove(token);
            right.remove(token);
            nonassoc.remove(token);


            listToken.updateUI();
            listToken1.updateUI();
            listToken2.updateUI();
            listToken4.updateUI();
            listToken4.updateUI();
            tokenNameTextField.setText("");
            tokenExpressionTextField.setText("");
            tipoToken.setSelectedIndex(0);

            listProduzioni.updateUI();
            listProduzioni1.updateUI();
            listLeft.updateUI();
            listRight.updateUI();
            listNonassoc.updateUI();
        }
    }//GEN-LAST:event_rimuoviTokenActionPerformed

    private void nuovoTokenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nuovoTokenActionPerformed

        tokenSelected = -1;
        tokenNameTextField.setText(null);
        tokenExpressionTextField.setText(null);
    }//GEN-LAST:event_nuovoTokenActionPerformed

    private void modificaTokenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_modificaTokenActionPerformed
        tokenSelected = listToken.getSelectedIndex();
        if (tokenSelected > -1) {
            Token t = tokens.get(tokenSelected);
            tokenNameTextField.setText(t.getName());
            tokenExpressionTextField.setText(t.getExpression());
            switch (t.getThisTokenType()) {
                case niente:
                    tipoToken.setSelectedItem("NOTHING");
                    break;
                case ival:
                    tipoToken.setSelectedItem("INTEGER");
                    break;
                case dval:
                    tipoToken.setSelectedItem("DOUBLE");
                    break;
                case sval:
                    tipoToken.setSelectedItem("STRING");
                    break;
                case obj:
                    tipoToken.setSelectedItem("OBJECT");
                    break;
                case ignora:
                    tipoToken.setSelectedItem("IGNORE");
                    break;

            }
        }
   }//GEN-LAST:event_modificaTokenActionPerformed

    private void inserisciTokenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inserisciTokenActionPerformed
        boolean valid = true;
        //Verifico se i dati inseriti sono accettabili
        if (!tokenNameTextField.getText().equals("") && !tokenExpressionTextField.getText().equals("")) {
            ListIterator<Token> it = tokens.listIterator();
            while (it.hasNext()) {


                Token t = it.next();

                if (t.getName().equals(tokenNameTextField.getText()) || t.getExpression().equals(tokenExpressionTextField.getText())) {
                    valid = false;
                    JOptionPane.showMessageDialog(null, " Esiste gia un Token con lo stesso nome o espressione regolare", "Token non valido", JOptionPane.ERROR_MESSAGE);
                    break;
                }
                if (tokenSelected > -1) {
                    if (it.nextIndex() == tokenSelected) {
                        if (it.hasNext()) {
                            it.next();
                        } else {
                            break;
                        }
                    }
                }
            }
            Iterator<NonTerminale> it2 = nonTerminali.iterator();
            while (it2.hasNext()) {
                NonTerminale nt = it2.next();
                if (nt.getName().equals(tokenNameTextField.getText())) {
                    valid = false;
                    JOptionPane.showMessageDialog(null, " Esiste gia un Non Terminale con lo stesso nome", "Token non valido", JOptionPane.ERROR_MESSAGE);
                    break;
                }
            }
        } else {
            valid = false;
            JOptionPane.showMessageDialog(null, " Nome Token o Espressione Regolare non Inserita", "Token non Valido", JOptionPane.ERROR_MESSAGE);
        }
        if (valid) {
            if (tokenSelected == -1) {
                Token token = new Token(tokenNameTextField.getText(), tokenExpressionTextField.getText());
                if (tipoToken.getSelectedIndex() > -1) {
                    int x = tipoToken.getSelectedIndex();
                    switch (x) {
                        case 1:
                            token.setThisTokenType(linguaggio.AttributeType.tokenType.ival);
                            break;
                        case 2:
                            token.setThisTokenType(linguaggio.AttributeType.tokenType.dval);
                            break;
                        case 3:
                            token.setThisTokenType(linguaggio.AttributeType.tokenType.sval);
                            break;
                        case 4:
                            token.setThisTokenType(AttributeType.tokenType.obj);
                            token.setTypeAttribute(JOptionPane.showInputDialog("Inserisci Nome Classe: "));
                            token.setCode(JOptionPane.showInputDialog("Inserisci Attributi per costruttore: "));
                            break;
                        case 5:
                            token.setThisTokenType(AttributeType.tokenType.ignora);
                            break;
                        case 0:
                            token.setThisTokenType(linguaggio.AttributeType.tokenType.niente);
                            break;
                    }
                }
                tokens.add(token);
            } else {
                Token token = tokens.get(tokenSelected);
                token.setName(tokenNameTextField.getText());
                token.setExpression(tokenExpressionTextField.getText());
                if (tipoToken.getSelectedIndex() > -1) {
                    int x = tipoToken.getSelectedIndex();
                    switch (x) {
                        case 1:
                            token.setThisTokenType(linguaggio.AttributeType.tokenType.ival);
                            break;
                        case 2:
                            token.setThisTokenType(linguaggio.AttributeType.tokenType.dval);
                            break;
                        case 3:
                            token.setThisTokenType(linguaggio.AttributeType.tokenType.sval);
                            break;
                        case 4:
                            token.setThisTokenType(AttributeType.tokenType.obj);
                            token.setTypeAttribute(JOptionPane.showInputDialog("Inserisci Nome Classe: "));
                            token.setCode(JOptionPane.showInputDialog("Inserisci Attributi per costruttore: "));
                            break;
                        case 5:
                            token.setThisTokenType(AttributeType.tokenType.ignora);
                            break;
                        case 0:
                            token.setThisTokenType(linguaggio.AttributeType.tokenType.niente);
                            break;
                    }
                }
            }
            tokenNameTextField.setText(null);
            tokenExpressionTextField.setText(null);
            listToken.updateUI();
            listToken1.updateUI();
            listToken2.updateUI();
            listToken3.updateUI();
            listToken4.updateUI();
        }

    }//GEN-LAST:event_inserisciTokenActionPerformed

    private void tokenNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tokenNameTextFieldActionPerformed
}//GEN-LAST:event_tokenNameTextFieldActionPerformed

private void parteSinistra1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_parteSinistra1ActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event_parteSinistra1ActionPerformed

private void aggiungiNTproduzioneErroreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aggiungiNTproduzioneErroreActionPerformed
    if (listNonTerminali2.getSelectedIndex() > -1) {
        NonTerminale nt = nonTerminali.get(listNonTerminali2.getSelectedIndex());
        parteDestra1.append(nt + " ");
        parteDestraSelezionata1.add(nt);
    }
}//GEN-LAST:event_aggiungiNTproduzioneErroreActionPerformed

private void aggiungiTProduzioneErroreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aggiungiTProduzioneErroreActionPerformed
    if (listToken3.getSelectedIndex() > -1) {
        Token token = tokens.get(listToken3.getSelectedIndex());
        parteDestra1.append(token + " ");
        parteDestraSelezionata1.add(token);
    }
}//GEN-LAST:event_aggiungiTProduzioneErroreActionPerformed

private void aggiungiProduzioneErroreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aggiungiProduzioneErroreActionPerformed
    boolean valid = true;
    ProduzioneErrore p = new ProduzioneErrore((NonTerminale) parteSinistra1.getSelectedItem(), parteDestraSelezionata1);
    if (!p.getParteDestra().contains(this.error)) {
        valid = false;
        JOptionPane.showMessageDialog(null, "La produzione non contiene la keyword error", "Produzione non Valida", JOptionPane.ERROR_MESSAGE);
    }
    if (valid) {
        if (p.getParteSinistra() == null || parteDestraSelezionata1.isEmpty()) {
            valid = false;
            JOptionPane.showMessageDialog(null, "Parte Sinistra o Destra vuota", "Produzione non Valida", JOptionPane.ERROR_MESSAGE);
        } else {
            Iterator<Produzione> it = produzioniErrore.iterator();
            while (it.hasNext()) {
                Produzione produzione = it.next();
                if (produzione.toString().equals(p.toString())) {
                    valid = false;
                    JOptionPane.showMessageDialog(null, "Produzione già esistente", "Produzione non Valida", JOptionPane.ERROR_MESSAGE);
                    break;
                }
            }
        }
    }

    if (valid) {
        produzioniErrore.add(p);
        parteSinistra1.setSelectedIndex(-1);
        parteDestraSelezionata1 = new LinkedList<Element>();
        parteDestra1.setText("");
        listProduzioniErrore.updateUI();
    }
}//GEN-LAST:event_aggiungiProduzioneErroreActionPerformed

private void rimuoviUltimoParteDestra1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rimuoviUltimoParteDestra1ActionPerformed
    if (!parteDestraSelezionata1.isEmpty()) {
        Element e = parteDestraSelezionata1.removeLast();
        String pd = parteDestra1.getText();
        parteDestra1.setText(pd.substring(0, pd.lastIndexOf(e.getName())));
    }
}//GEN-LAST:event_rimuoviUltimoParteDestra1ActionPerformed

private void ripulisciParteDestra1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ripulisciParteDestra1ActionPerformed
    parteDestraSelezionata1 = new LinkedList<Element>();
    parteDestra1.setText("");
}//GEN-LAST:event_ripulisciParteDestra1ActionPerformed

private void eliminaProduzioneErroreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_eliminaProduzioneErroreActionPerformed
    int index = listProduzioniErrore.getSelectedIndex();
    if (index > -1) {
        produzioniErrore.remove(index);
    }
    listProduzioniErrore.updateUI();
}//GEN-LAST:event_eliminaProduzioneErroreActionPerformed

    private void aggiungiErrorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aggiungiErrorActionPerformed

        parteDestra1.append(error + " ");
        parteDestraSelezionata1.add(error);

    }//GEN-LAST:event_aggiungiErrorActionPerformed

    private void parteSinistra2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_parteSinistra2ActionPerformed
    }//GEN-LAST:event_parteSinistra2ActionPerformed

    private void aggiungiAperturaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aggiungiAperturaActionPerformed
        if (listToken4.getSelectedIndex() > -1) {
            Token t = tokens.get(listToken4.getSelectedIndex());
            if (!marcaApertura.contains(t)) {
                marcaApertura.add(t);
                listMarcaApertura.updateUI();
            }

        }
    }//GEN-LAST:event_aggiungiAperturaActionPerformed
    private void aggiungiChiusuraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aggiungiChiusuraActionPerformed
        if (listToken4.getSelectedIndex() > -1) {
            Token t = tokens.get(listToken4.getSelectedIndex());
            if (!marcaChiusura.contains(t)) {
                marcaChiusura.add(t);
                listMarcaChiusura.updateUI();
            }
        }
    }//GEN-LAST:event_aggiungiChiusuraActionPerformed

    private void rimuoviChiusuraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rimuoviChiusuraActionPerformed
        if (listMarcaChiusura.getSelectedIndex() > -1) {
            marcaChiusura.remove(listMarcaChiusura.getSelectedIndex());
            listMarcaChiusura.clearSelection();
            listMarcaChiusura.updateUI();
        }
    }//GEN-LAST:event_rimuoviChiusuraActionPerformed

    private void rimuoviAperturaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rimuoviAperturaActionPerformed
        if (listMarcaApertura.getSelectedIndex() > -1) {
            marcaApertura.remove(listMarcaApertura.getSelectedIndex());
            listMarcaApertura.clearSelection();
            listMarcaApertura.updateUI();
        }
    }//GEN-LAST:event_rimuoviAperturaActionPerformed

    private void salvaSincroTriplaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salvaSincroTriplaActionPerformed

        if (parteSinistra2.getSelectedIndex() > -1) {
            boolean found = false;
            Iterator<SincroTripla> it = sincroTriple.iterator();
            while (it.hasNext()) {
                SincroTripla s = it.next();
                if (s.getNonTerminale().equals(parteSinistra2.getSelectedItem())) {
                    s.setMarcaApertura(new LinkedList<>(marcaApertura));
                    s.setMarcaChiusura(new LinkedList<>(marcaChiusura));
                    found = true;
                    break;
                }
            }
            if (!found) {
                sincroTriple.add(new SincroTripla((NonTerminale) parteSinistra2.getSelectedItem(), new LinkedList<>(marcaApertura), new LinkedList<>(marcaChiusura)));

            }
        } else {
            JOptionPane.showMessageDialog(null, " Nessun Non Terminale Selezionato ", "SincroTripla non Valida", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_salvaSincroTriplaActionPerformed

    private void panicModeRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_panicModeRadioButtonActionPerformed
        errorType = Grammatica.ErrorType.panicMode;
        sincroTriple = new LinkedList<>();
        marcaApertura.removeAllElements();
        marcaChiusura.removeAllElements();
        produzioniErrore.removeAllElements();
        //listMarcaApertura.setListData(marcaApertura);
        //listMarcaChiusura.setListData(marcaChiusura);
        jTabbedPane4.setEnabledAt(2, true);
        jTabbedPane4.setEnabledAt(1, false);
    }//GEN-LAST:event_panicModeRadioButtonActionPerformed

    private void produzioniErroriRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_produzioniErroriRadioButtonActionPerformed
        errorType = Grammatica.ErrorType.produzioniErrori;
        produzioniErrore.removeAllElements();
        jTabbedPane4.setEnabledAt(1, true);
        jTabbedPane4.setEnabledAt(2, false);
    }//GEN-LAST:event_produzioniErroriRadioButtonActionPerformed

    private void parteSinistra2ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_parteSinistra2ItemStateChanged

        int index = parteSinistra2.getSelectedIndex();
        if (index > -1) {
            NonTerminale nt = nonTerminali.get(index);
            marcaApertura.removeAllElements();
            marcaChiusura.removeAllElements();
            Iterator<SincroTripla> it = sincroTriple.iterator();
            while (it.hasNext()) {
                SincroTripla st = it.next();
                if (st.getNonTerminale().equals(nt)) {
                    marcaApertura.addAll(st.getMarcaApertura());
                    marcaChiusura.addAll(st.getMarcaChiusura());

                    break;
                }
            }
            listMarcaApertura.updateUI();
            listMarcaChiusura.updateUI();
        }
    }//GEN-LAST:event_parteSinistra2ItemStateChanged

    private void spostaSopraProduzioneErroreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_spostaSopraProduzioneErroreActionPerformed
        int startIndex = listProduzioniErrore.getSelectedIndex();
        if (startIndex > 0 && startIndex < produzioniErrore.size()) {
            produzioniErrore.set(startIndex, produzioniErrore.set(startIndex - 1, produzioniErrore.get(startIndex)));
            listProduzioniErrore.setSelectedIndex(startIndex - 1);
            listProduzioniErrore.updateUI();
        }
    }//GEN-LAST:event_spostaSopraProduzioneErroreActionPerformed

    private void spostaSottoProduzioneErroreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_spostaSottoProduzioneErroreActionPerformed
        int startIndex = listProduzioniErrore.getSelectedIndex();
        if (startIndex > -1 && startIndex < produzioniErrore.size() - 1) {
            produzioniErrore.set(startIndex, produzioniErrore.set(startIndex + 1, produzioniErrore.get(startIndex)));
            listProduzioniErrore.setSelectedIndex(startIndex + 1);
            listProduzioniErrore.updateUI();
        }
    }//GEN-LAST:event_spostaSottoProduzioneErroreActionPerformed

    private void rimuoviRegolaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rimuoviRegolaActionPerformed
        if (produzioneSelezionata > -1) {
            produzioni.get(produzioneSelezionata).setRegolaSemantica("");
            produzioneSelezionata = -1;
            listProduzioni1.clearSelection();
            produzioneSelezionataLabel.setText("Nessuna");
            regolaSemantica.setText(null);
        }
    }//GEN-LAST:event_rimuoviRegolaActionPerformed

    private void implementaParserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_implementaParserActionPerformed
        Grammatica g = creaGrammatica();
        String result;
        if (g.getErrorType().equals(ErrorType.panicMode)) {
            ListIterator<SincroTripla> it = sincroTriple.listIterator();
            SincroTripla s;
            
            while (it.hasNext()) {
                s = it.next();
                result = Controller.controlSincrotripla(g,s);
                if(!result.equals("")){
                    int response = JOptionPane.showConfirmDialog(null, result+"\nSei sicuro di voler continuare?","Problema nella Sincrotripla", JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);
                    if(response == JOptionPane.NO_OPTION)return;
                }
            }
        }
        result = Controller.control(g);
        if(!result.equals("")){
            JOptionPane.showMessageDialog(null, result, "Problema nella Grammatica", JOptionPane.ERROR_MESSAGE);
            return;
        }
        Generatore gen = new Generatore(g, "Parser.y", "Scanner.lex");
        String output = gen.generaScanner();
        if (output != null) {
            JOptionPane.showMessageDialog(null, "Generazione Scanner Fallita:\n" + output, "Generazione Fallita", JOptionPane.ERROR_MESSAGE);
            return;
        }
        output = gen.generaParser();
        if (output != null) {
            JOptionPane.showMessageDialog(null, "Generazione Parser Fallita:\n" + output, "Generazione Fallita", JOptionPane.ERROR_MESSAGE);
            return;
        }
        if (!gen.generaMain()) {
            JOptionPane.showMessageDialog(null, "Generazione Main Fallita", "Generazione Fallita", JOptionPane.ERROR_MESSAGE);
            return;
        }
        JOptionPane.showMessageDialog(null, "Grammatica Generata Correttamente", "Generazione Grammatica", JOptionPane.PLAIN_MESSAGE);
    }//GEN-LAST:event_implementaParserActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        new Start().setVisible(true);
    }//GEN-LAST:event_formWindowClosed

    private void spostaSopraNTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_spostaSopraNTActionPerformed
        int startIndex = listNonTerminali3.getSelectedIndex();
        if (startIndex > 0 && startIndex < nonTerminali.size()) {
            nonTerminali.set(startIndex, nonTerminali.set(startIndex - 1, nonTerminali.get(startIndex)));
            listNonTerminali3.setSelectedIndex(startIndex - 1);
            listNonTerminali1.updateUI();
            listNonTerminali2.updateUI();
            listNonTerminali3.updateUI();
        }
    }//GEN-LAST:event_spostaSopraNTActionPerformed

    private void spostaSottoNTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_spostaSottoNTActionPerformed
        int startIndex = listNonTerminali3.getSelectedIndex();
        if (startIndex > -1 && startIndex < nonTerminali.size() - 1) {
            nonTerminali.set(startIndex, nonTerminali.set(startIndex + 1, nonTerminali.get(startIndex)));
            listNonTerminali3.setSelectedIndex(startIndex + 1);
            listNonTerminali1.updateUI();
            listNonTerminali2.updateUI();
            listNonTerminali3.updateUI();
        }
    }//GEN-LAST:event_spostaSottoNTActionPerformed

    private void selezionaNTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selezionaNTActionPerformed
        if (listNonTerminali3.getSelectedIndex() > -1) {
            produzioniNonTerminale.removeAllElements();
            NonTerminale nt = nonTerminali.get(listNonTerminali3.getSelectedIndex());
            Iterator<Produzione> it = produzioni.iterator();
            while (it.hasNext()) {
                Produzione p = it.next();
                if (p.getParteSinistra().equals(nt)) {
                    produzioniNonTerminale.add(p);
                }
            }
            listProduzioniNT.updateUI();
        }
    }//GEN-LAST:event_selezionaNTActionPerformed

    private void spostaSopraProduzioneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_spostaSopraProduzioneActionPerformed
        int startIndex = listProduzioniNT.getSelectedIndex();
        if (startIndex > 0 && startIndex < produzioniNonTerminale.size()) {
            scambiaProduzioni(produzioniNonTerminale.get(startIndex), produzioniNonTerminale.get(startIndex - 1));
            produzioniNonTerminale.set(startIndex, produzioniNonTerminale.set(startIndex - 1, produzioniNonTerminale.get(startIndex)));
            listProduzioniNT.setSelectedIndex(startIndex - 1);
            listProduzioniNT.updateUI();
        }
    }//GEN-LAST:event_spostaSopraProduzioneActionPerformed
    private void scambiaProduzioni(Produzione p1, Produzione p2) {
        int index1 = produzioni.indexOf(p1);
        int index2 = produzioni.indexOf(p2);
        produzioni.set(index1, p2);
        produzioni.set(index2, p1);
    }
    private void spostaSottoProduzioneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_spostaSottoProduzioneActionPerformed
        int startIndex = listProduzioniNT.getSelectedIndex();
        if (startIndex > -1 && startIndex < produzioniNonTerminale.size() - 1) {
            scambiaProduzioni(produzioniNonTerminale.get(startIndex), produzioniNonTerminale.get(startIndex + 1));
            produzioniNonTerminale.set(startIndex, produzioniNonTerminale.set(startIndex + 1, produzioniNonTerminale.get(startIndex)));
            listProduzioniNT.setSelectedIndex(startIndex + 1);
            listProduzioniNT.updateUI();
        }
    }//GEN-LAST:event_spostaSottoProduzioneActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;










                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Menu().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane ScrollPaneProduzioni;
    private javax.swing.JButton aggiungiApertura;
    private javax.swing.JButton aggiungiChiusura;
    private javax.swing.JButton aggiungiError;
    private javax.swing.JButton aggiungiLeft;
    private javax.swing.JButton aggiungiNTproduzione;
    private javax.swing.JButton aggiungiNTproduzioneErrore;
    private javax.swing.JButton aggiungiNonAssoc;
    private javax.swing.JButton aggiungiProduzione;
    private javax.swing.JButton aggiungiProduzioneErrore;
    private javax.swing.JButton aggiungiRegola;
    private javax.swing.JButton aggiungiRight;
    private javax.swing.JButton aggiungiTProduzione;
    private javax.swing.JButton aggiungiTProduzioneErrore;
    private javax.swing.ButtonGroup buttonGroup;
    private javax.swing.JButton eliminaProduzione;
    private javax.swing.JButton eliminaProduzioneErrore;
    private javax.swing.JButton implementaParser;
    private javax.swing.JButton inserisciNT;
    private javax.swing.JButton inserisciToken;
    private javax.swing.JFileChooser jFileChooser1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanelLessico;
    private javax.swing.JPanel jPanelNT;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane10;
    private javax.swing.JScrollPane jScrollPane11;
    private javax.swing.JScrollPane jScrollPane12;
    private javax.swing.JScrollPane jScrollPane13;
    private javax.swing.JScrollPane jScrollPane14;
    private javax.swing.JScrollPane jScrollPane15;
    private javax.swing.JScrollPane jScrollPane16;
    private javax.swing.JScrollPane jScrollPane17;
    private javax.swing.JScrollPane jScrollPane18;
    private javax.swing.JScrollPane jScrollPane19;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane20;
    private javax.swing.JScrollPane jScrollPane21;
    private javax.swing.JScrollPane jScrollPane22;
    private javax.swing.JScrollPane jScrollPane23;
    private javax.swing.JScrollPane jScrollPane24;
    private javax.swing.JScrollPane jScrollPane25;
    private javax.swing.JScrollPane jScrollPane26;
    private javax.swing.JScrollPane jScrollPane27;
    private javax.swing.JScrollPane jScrollPane28;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JScrollPane jScrollPane9;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTabbedPane jTabbedPane2;
    private javax.swing.JTabbedPane jTabbedPane3;
    private javax.swing.JTabbedPane jTabbedPane4;
    private javax.swing.JList listLeft;
    private javax.swing.JList listMarcaApertura;
    private javax.swing.JList listMarcaChiusura;
    private javax.swing.JList listNonTerminali;
    private javax.swing.JList listNonTerminali1;
    private javax.swing.JList listNonTerminali2;
    private javax.swing.JList listNonTerminali3;
    private javax.swing.JList listNonassoc;
    private javax.swing.JList listProduzioni;
    private javax.swing.JList listProduzioni1;
    private javax.swing.JList listProduzioniErrore;
    private javax.swing.JList listProduzioniNT;
    private javax.swing.JList listRight;
    private javax.swing.JList listToken;
    private javax.swing.JList listToken1;
    private javax.swing.JList listToken2;
    private javax.swing.JList listToken3;
    private javax.swing.JList listToken4;
    private javax.swing.JButton modificaToken;
    private javax.swing.JTextField nonTerminaleName;
    private javax.swing.JButton nuovoToken;
    private javax.swing.JRadioButton panicModeRadioButton;
    private javax.swing.JTextArea parteDestra;
    private javax.swing.JTextArea parteDestra1;
    private javax.swing.JComboBox parteSinistra;
    private javax.swing.JComboBox parteSinistra1;
    private javax.swing.JComboBox parteSinistra2;
    private javax.swing.JLabel produzioneSelezionataLabel;
    private javax.swing.JScrollPane produzioniErroriPane;
    private javax.swing.JRadioButton produzioniErroriRadioButton;
    private javax.swing.JTextArea regolaSemantica;
    private javax.swing.JButton rimuoviApertura;
    private javax.swing.JButton rimuoviChiusura;
    private javax.swing.JButton rimuoviLeft;
    private javax.swing.JButton rimuoviNT;
    private javax.swing.JButton rimuoviNonAssoc;
    private javax.swing.JButton rimuoviRegola;
    private javax.swing.JButton rimuoviRight;
    private javax.swing.JButton rimuoviToken;
    private javax.swing.JButton rimuoviUltimoParteDestra;
    private javax.swing.JButton rimuoviUltimoParteDestra1;
    private javax.swing.JButton ripulisciParteDestra;
    private javax.swing.JButton ripulisciParteDestra1;
    private javax.swing.JButton salvaGrammatica;
    private javax.swing.JButton salvaSincroTripla;
    private javax.swing.JButton selezionaNT;
    private javax.swing.JButton selezionaProduzione;
    private javax.swing.JScrollPane sincrotriplePane;
    private javax.swing.JButton spostaSopraLeft;
    private javax.swing.JButton spostaSopraNT;
    private javax.swing.JButton spostaSopraNonAssoc;
    private javax.swing.JButton spostaSopraProduzione;
    private javax.swing.JButton spostaSopraProduzioneErrore;
    private javax.swing.JButton spostaSopraRight;
    private javax.swing.JButton spostaSottoLeft;
    private javax.swing.JButton spostaSottoNT;
    private javax.swing.JButton spostaSottoNonAssoc;
    private javax.swing.JButton spostaSottoProduzione;
    private javax.swing.JButton spostaSottoProduzioneErrore;
    private javax.swing.JButton spostaSottoRight;
    private javax.swing.JComboBox tipoNT;
    private javax.swing.JComboBox tipoToken;
    private javax.swing.JTextArea tokenExpressionTextField;
    private javax.swing.JTextField tokenNameTextField;
    // End of variables declaration//GEN-END:variables
}
